package com.tjsinfo.tjsoa.worklog.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.PageController;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;
import com.tjsinfo.tjsoa.worklog.dao.IWorkLogMainDao;
import com.tjsinfo.tjsoa.worklog.vo.WorkLogMain;


public class CheckworkLogYearModleAction extends Action{
	private IWorkLogMainDao workLogMainDao;

	public IWorkLogMainDao getWorkLogMainDao() {
		return workLogMainDao;
	}

	public void setWorkLogMainDao(IWorkLogMainDao workLogMainDao) {
		this.workLogMainDao = workLogMainDao;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		WorkLogMain workLogMain = new WorkLogMain();
		TSystemUser tjsUser = new TSystemUser();
		tjsUser.setUserId(Integer.parseInt(request.getParameter("id")));
		workLogMain.setTjsUser(tjsUser);
		workLogMain.setType("Y");
		workLogMain.setSubmittype(0);
		List list  = 	workLogMainDao.checkDefaultWorkLogYear(workLogMain);
		Integer contentspage = null;
		String start = null;
		 PageController pageController = new PageController();
		    if(request.getParameter("page") != null && request.getParameter("start") == null )
			{
				pageController.setPageController(list);
				pageController.setMaxPageRows(18);
				list = (ArrayList) pageController.getPageContents(Integer.parseInt(request.getParameter("page") ));
		
			}
		    else if (request.getParameter("page") != null) {
				contentspage = Integer.parseInt(request.getParameter("page"));
				start = request.getParameter("start");
				pageController.setPageController(list);
				pageController.setMaxPageRows(18);
				if (start.equals("up")) {
					list = (ArrayList) pageController
							.getPageContents(contentspage - 1);
				} else if(start.equals("down")) {
					list = (ArrayList) pageController
							.getPageContents(contentspage + 1);
				}
				else if(start.equals("first"))
				{
					list = (ArrayList) pageController
					.getPageContents(1);
				}
				else if(start.equals("last"))
				{
					list = (ArrayList) pageController
					.getPageContents(pageController.getPageCount());
				}
			} else {
				pageController.setPageController(list);
				pageController.setMaxPageRows(18);
				list = (ArrayList) pageController.getPageContents(1);
			}
		request.setAttribute("list", list);
		request.setAttribute("pageController",pageController);
		request.setAttribute("userid", Integer.parseInt(request.getParameter("id")));
		return mapping.findForward("ok");
	}
	
	
}
